/**
 * 
 */
package id.web.faisalabdillah.xtimesheet.services.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import id.web.faisalabdillah.xtimesheet.dao.IUserDao;
import id.web.faisalabdillah.xtimesheet.domain.User;
import id.web.faisalabdillah.xtimesheet.services.IUserService;

/**
 * @author faitz
 *
 */
@Service
@Transactional(readOnly=true)
public class UserServiceImpl implements IUserService {

	@Autowired
	private IUserDao userDao;
	
	/* (non-Javadoc)
	 * @see id.web.faisalabdillah.xtimesheet.services.IUserService#insert(id.web.faisalabdillah.xtimesheet.domain.User)
	 */
	@Override
	@Transactional(readOnly=false)
	public boolean insert(User user) {
		try {
			userDao.insert(user);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
	}

	/* (non-Javadoc)
	 * @see id.web.faisalabdillah.xtimesheet.services.IUserService#update(id.web.faisalabdillah.xtimesheet.domain.User)
	 */
	@Override
	@Transactional(readOnly=false)
	public boolean update(User user) {
		try {
			userDao.update(user);
			return true;
		} catch (Exception e) {
			return false;
		}
	}

	/* (non-Javadoc)
	 * @see id.web.faisalabdillah.xtimesheet.services.IUserService#remove(java.lang.String)
	 */
	@Override
	@Transactional(readOnly=false)
	public boolean remove(String user) {
		try {
			userDao.remove(findById(user));
			return true;
		} catch (Exception e) {
			return false;
		}
	}

	/* (non-Javadoc)
	 * @see id.web.faisalabdillah.xtimesheet.services.IUserService#listAll()
	 */
	@Override
	public List<User> listAll() {
		return userDao.listAll();
	}

	/* (non-Javadoc)
	 * @see id.web.faisalabdillah.xtimesheet.services.IUserService#listAllPaged(int, int)
	 */
	@Override
	public List<User> listAllPaged(int first, int max) {
		return userDao.listAllPaged(first, max);
	}

	/* (non-Javadoc)
	 * @see id.web.faisalabdillah.xtimesheet.services.IUserService#searchByName(java.lang.String)
	 */
	@Override
	public List<User> searchByName(String name) {
		return userDao.searchByName(name);
	}

	/* (non-Javadoc)
	 * @see id.web.faisalabdillah.xtimesheet.services.IUserService#searchByNamePaged(java.lang.String, int, int)
	 */
	@Override
	public List<User> searchByNamePaged(String name, int first, int max) {
		return userDao.searchByNamePaged(name, first, max);
	}

	/* (non-Javadoc)
	 * @see id.web.faisalabdillah.xtimesheet.services.IUserService#findById(java.lang.String)
	 */
	@Override
	public User findById(String id) {
		return userDao.findById(id);
	}

	/* (non-Javadoc)
	 * @see id.web.faisalabdillah.xtimesheet.services.IUserService#sizeAll()
	 */
	@Override
	public int sizeAll() {
		return userDao.sizeAll();
	}

	/* (non-Javadoc)
	 * @see id.web.faisalabdillah.xtimesheet.services.IUserService#searchByNameSize(java.lang.String)
	 */
	@Override
	public int searchByNameSize(String name) {
		return userDao.searchByNameSize(name);
	}
	
}
